package com.subsequent.method;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class LoginStrategyFactory {
    private final Map<String, LoginStrategy> strategies = new ConcurrentHashMap<>();

    @Autowired
    public LoginStrategyFactory(Map<String, LoginStrategy> strategyMap) {
        strategyMap.forEach((key, value) -> strategies.put(key, value));
    }

    public LoginStrategy getStrategy(String loginType) {
        LoginStrategy strategy = strategies.get(loginType + "LoginStrategy");
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的登录类型: " + loginType);
        }
        return strategy;
    }
}
